<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
	</head>
	<body>
		<body>
			<button onclick="openClick()">开始</button>
			<button onclick="handleClick()">改变a的值</button>
		</body>
		<script>
			// React中 类组件 与 函数组件 的区别
			// https://blog.csdn.net/qq_38970408/article/details/136966281
			function parent(arg) {
				let a = arg;
				return function children() {
					alert('a的值是：' + a);
				}
			}
			function openClick() {
				setTimeout(() => {
					parent(111)();
				}, 3000);
			}
			function handleClick() {
				parent(222);
			}

			var f1 = function() {
				var va = '局部变量'
				return function() {
					return va
				}
			}
			var va = f1()()
			console.log(va, '局部变量')

			var f2 = function() {
				var num = 0
				return function() {
					num++
					return num
				}
			}
			var f2 = f2()
			// console.log(f2()(), f2()(), f2()(), 'add')
			console.log(f2(), f2(), f2(), 'add')

			var f3 = function() {
				var arr = []
				for (var i = 0; i < 5; i++) {
					arr[i] = (function() {
						return '元素' + i
					})()
				}
				return arr
			}
			var f3 = f3()
			console.log(f3, 'fn_arr[i]')

			var f3_1 = function() {
				var arr = []
				for (var i = 0; i < 5; i++) {
					// arr[i] = (function() {
					// 	return function() {
					// 	  return '元素' + i
					//   }()
					// })()
					arr[i] = function(n) {
						return function() {
							return '元素' + n
						}
					}(i)
				}
				return arr
			}
			var f3_1_fn = f3_1()
			for (var i in f3_1_fn) {
				var val = f3_1_fn[i]
				// console.log(val, 'fn_fn_arr[i]')
				console.log(val(), 'fn_fn_arr[i]')
			}

			(function() {
				for (var i = 0; i < 5; i++) {
					// for (let i = 0; i < 5; i++) {
					setTimeout(() => {
						console.log(i, '块级作用域1')
					})
				}
			})()
			for (var i = 0; i < 5; i++) {
				(function(n) {
					setTimeout(() => {
						console.log(n, '块级作用域2')
					})
				})(i)
			}
			console.log(i, '块级作用域3')

			;
			(function() {
				var name = '张三'
				USER = function() {}
				USER.prototype.getName = function() {
					return name
				}
				USER.prototype.setName = function(val) {
					name = val
				}
			})()
			var user = new USER()
			console.log(user.getName(), 'get静态私有变量')
			user.setName('李四')
			console.log(user.getName(), 'set静态私有变量')
		</script>
	</body>
</html>